<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<link rel="stylesheet" href="./css/register.css">
<script src="../lib/jquery/jquery-1.12.4.min.js"></script>
<!-- <link rel="stylesheet" href="../lib/reset.css/reset.css"> -->
<script src="./url.js"></script>

<body>
    <div class="wrap">
        <div class="head">
            <h1>
                <img src="./images/logo.jpg" alt="">
                美发管理系统
            </h1>
        </div>
        <form action="post">
            <div class="middle">
                <div class="top">
                    <span>用户名</span>
                    <input type="text" name="username" class="user">
                </div>
                <div class="center">
                    <span>&nbsp;&nbsp; 密码</span>
                    <input type="text">
                </div>
                <div class="bottom">
                    <span>确认密码</span>
                    <input type="text" name="password" class="password">
                </div>
            </div>
            <div class="foot">
                <div>
                    <button class="test1">注册</button>
                    <button class="test2">登录</button>
                </div>
            </div>
        </form>
    </div>
    <script>
        $(".test1").click((e) => {
            e.preventDefault()
            $.ajax({
                method: "post",
                url: `${Baseurl}/reg`,
                data: {
                    username: $(".user").val(),
                    password: $(".password").val()
                },
                success: function (data) {
                    if (data == "用户名已存在") {
                        alert("用户名已存在")
                    } else if (data == "注册成功") {
                        alert("注册成功,请前往登录")
                        window.location = "./login.html"
                    } else {
                        alert("格式错误")
                    }
                }
            })
        })
    </script>
</body>

</html>